The SimpleMenu Component > Using the SimpleMenu component > Creating a Click Handler

 

Creating a Click Handler

In order to receive notification of an item on the SimpleMenu being clicked, you need to create a Click Handler—a function that's invoked when a particular event occurs. The Click Handler function is passed two parameters: one that indicates which SimpleMenu component was clicked (this is mainly if you have more than one instance of the SimpleMenu component on stage) and one that indicates the index of the item which was clicked.

To set up a Click Handler:

1

Create a new file in Macromedia Flash MX.

2

Select the Flash UI Component Set item on the Component panel (Window > Components).

3

Drag the SimpleMenu icon onto the stage.

4

Select the SimpleMenu and enter the following into the Item List property:

 

Company Info
Company Profile
Employment
fsm_bar
Contact

Note: these can be anything you like.

5

Enter _handleClickSM in the Click Handler property.

6

Select the first keyframe and enter the following ActionScript:

 

_handleClickSM = function (component, index) {
    trace("The item at index " + index + " on " + component + " was clicked.");
}

7

Select Control > Test Movie to see the results of the Click Handler. Some information about whichever item is clicked should appear in the Output window.

8

The trace statement in the _handleClickSM function should be something more useful than a trace statement such as this:

 

if (index == 0) {
    gotoAndStop("company_info");
} else if (index == 1) {
    gotoAndStop("company_profile");
} else if (index == 2) {
    gotoAndStop("employment");
} else if (index == 4) {
    gotoAndStop("contact");
}